package io.gitee.zhucan123.core.infrastructure.exception.advice;

import com.niimbot.middlend.core.infrastructure.exception.NumberGeneratorException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: zlw 处理流水号生产失败异常
 * @Date: 2019/8/15 15:31
 * @Description:
 */
@RestControllerAdvice
@Slf4j
public class NumberGeneratorExceptionAdvice {

  @ExceptionHandler(NumberGeneratorException.class)
  @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
  public ErrorDTO handleCannotOperateException(HttpServletRequest req, NumberGeneratorException ex) {
    String errorMessage = ex.getMessage();
    String errorURL = req.getRequestURL().toString();
    return new ErrorDTO(errorMessage, HttpStatus.INTERNAL_SERVER_ERROR.value(), errorURL);
  }
}
